package com.sky.mapper;

import com.sky.annotation.AutoFillUserId;
import com.sky.entity.AddressBook;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    /**
     * 新增收货地址
     * @param addressBook
     */
    @Select("insert into address_book(user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label,is_default) " +
            "values(#{userId}, #{consignee},  #{sex},#{phone}, #{provinceCode}, #{provinceName}, #{cityCode}, #{cityName},#{districtCode}, #{districtName}, #{detail}, #{label}, #{isDefault})")
    @AutoFillUserId(OperationType.ADDVALUETOOBJECT)
    void add(AddressBook addressBook);

    /**
     * 查询登录用户所有地址
     * @param userId
     * @return
     */
    @AutoFillUserId(OperationType.ADDARG)
    @Select("select * from address_book where user_id=#{userId}")
    List<AddressBook> getAddressByUserId(Long userId);

    /**
     * 查询默认地址
     * @param addressBook
     * @return
     */
    @AutoFillUserId(OperationType.ADDVALUETOOBJECT)
    AddressBook getAddress(AddressBook addressBook);

    /**
     * 修改地址
     * @param addressBook
     */
    void updateAddress(AddressBook addressBook);

    /**
     * 根据id删除地址
     * @param id
     */
    @Delete("delete from address_book where id=#{id}")
    void deleteAddressById(Long id);
}
